﻿using Farming.Domain;
using Microsoft.EntityFrameworkCore;

namespace Farming.EntityFrameworkCore
{
    public class FarmingDbContext:DbContext
    {
        public FarmingDbContext(DbContextOptions<FarmingDbContext> options) : base(options) { }
        public DbSet<Admin> Admins { get; set; }

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.Entity<Admin>(d =>
            {
                d.Property(d => d.UserName).HasMaxLength(50).IsRequired();
            });
            //数据播种
            modelBuilder.Entity<Admin>().HasData(
             new Admin
            {
                 UserName = "Admin",
                 PassWord = Guid.NewGuid().ToString("n"),
                 AdminId = 1,
                 CreateById = 1,
                 CreateByName = "Admin",
                 CreateTime = DateTime.Now,
                 IsDeleted = false
             },
             new Admin
             {
                 UserName = "Admin2",
                 PassWord = Guid.NewGuid().ToString("n"),
                 AdminId = 2,
                 CreateById = 2,
                 CreateByName = "Admin2",
                 CreateTime = DateTime.Now.AddDays(6),
                 IsDeleted = false
             }
             
             );

            base.OnModelCreating(modelBuilder);
        }

    }
}